

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="zh" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="zh" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Visualization &mdash; Optuna 1.4.0 文档</title>
  

  
  
    <link rel="shortcut icon" href="../_static/favicon.ico"/>
  
  
  

  
  <script type="text/javascript" src="../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
        <script src="../_static/jquery.js"></script>
        <script src="../_static/underscore.js"></script>
        <script src="../_static/doctools.js"></script>
        <script src="../_static/language_data.js"></script>
        <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/custom.css" type="text/css" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="常见问题" href="../faq.html" />
    <link rel="prev" title="Trial" href="trial.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../index.html" class="icon icon-home"> Optuna
          

          
          </a>

          
            
            
              <div class="version">
                1.4.0
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">目录</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../installation.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">教程</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">API Reference</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="core.html">Core</a></li>
<li class="toctree-l2"><a class="reference internal" href="cli.html">Command Line Interface</a></li>
<li class="toctree-l2"><a class="reference internal" href="distributions.html">Distributions</a></li>
<li class="toctree-l2"><a class="reference internal" href="exceptions.html">Exceptions</a></li>
<li class="toctree-l2"><a class="reference internal" href="importance.html">Hyperparameter Importance</a></li>
<li class="toctree-l2"><a class="reference internal" href="integration.html">Integration</a></li>
<li class="toctree-l2"><a class="reference internal" href="logging.html">Logging</a></li>
<li class="toctree-l2"><a class="reference internal" href="multi_objective/index.html">Multi-objective</a></li>
<li class="toctree-l2"><a class="reference internal" href="pruners.html">Pruners</a></li>
<li class="toctree-l2"><a class="reference internal" href="samplers.html">Samplers</a></li>
<li class="toctree-l2"><a class="reference internal" href="storages.html">Storages</a></li>
<li class="toctree-l2"><a class="reference internal" href="structs.html">Structs</a></li>
<li class="toctree-l2"><a class="reference internal" href="study.html">Study</a></li>
<li class="toctree-l2"><a class="reference internal" href="trial.html">Trial</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Visualization</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../faq.html">常见问题</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">Optuna</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> &raquo;</li>
        
          <li><a href="index.html">API Reference</a> &raquo;</li>
        
      <li>Visualization</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../_sources/reference/visualization.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <span class="target" id="module-optuna.visualization"></span><div class="section" id="visualization">
<h1>Visualization<a class="headerlink" href="#visualization" title="永久链接至标题">¶</a></h1>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p><a class="reference internal" href="#module-optuna.visualization" title="optuna.visualization"><code class="xref py py-mod docutils literal notranslate"><span class="pre">visualization</span></code></a> 采用 plotly 来创建图表，但是 <a class="reference external" href="https://github.com/jupyterlab/jupyterlab">JupyterLab</a> 无法在默认情况下渲染这些图表。请按照这个 <a class="reference external" href="https://github.com/plotly/plotly.py#jupyterlab-support-python-35">installation guide</a> 来配置 <a class="reference external" href="https://github.com/jupyterlab/jupyterlab">JupyterLab</a> 中的图表显示。</p>
</div>
<dl class="py function">
<dt id="optuna.visualization.plot_contour">
<code class="sig-prename descclassname">optuna.visualization.</code><code class="sig-name descname">plot_contour</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">study</span><span class="p">:</span> <span class="n"><a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study">optuna.study.Study</a></span></em>, <em class="sig-param"><span class="n">params</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span>List<span class="p">[</span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a><span class="p">]</span><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em><span class="sig-paren">)</span> &#x2192; go.Figure<a class="reference internal" href="../_modules/optuna/visualization/_contour.html#plot_contour"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.visualization.plot_contour" title="永久链接至目标">¶</a></dt>
<dd><p>将参数关系画成等高线图。</p>
<p>注意，如果某个参数包含了缺失值，那么包含该参数的 trial 将不会被绘制。</p>
<p class="rubric">示例</p>
<p>下面的代码展示了如何将参数关系画成一个等高线图。</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">optuna</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">x</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_uniform</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="o">-</span><span class="mi">100</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
    <span class="n">y</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_categorical</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">x</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">y</span>

<span class="n">study</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">create_study</span><span class="p">()</span>
<span class="n">study</span><span class="o">.</span><span class="n">optimize</span><span class="p">(</span><span class="n">objective</span><span class="p">,</span> <span class="n">n_trials</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>

<span class="n">optuna</span><span class="o">.</span><span class="n">visualization</span><span class="o">.</span><span class="n">plot_contour</span><span class="p">(</span><span class="n">study</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="s1">&#39;y&#39;</span><span class="p">])</span>
</pre></div>
</div>
<iframe src="../_static/plot_contour.html" width="100%" height="500px" frameborder="0">
</iframe><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>study</strong> -- <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 类，其包含的 trials 的目标函数值将参与绘图。</p></li>
<li><p><strong>params</strong> -- 需要可视化的参数列表，默认情况下将是全部参数。</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p>A <code class="xref py py-class docutils literal notranslate"><span class="pre">plotly.graph_objs.Figure</span></code> object.</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt id="optuna.visualization.plot_intermediate_values">
<code class="sig-prename descclassname">optuna.visualization.</code><code class="sig-name descname">plot_intermediate_values</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">study</span><span class="p">:</span> <span class="n"><a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study">optuna.study.Study</a></span></em><span class="sig-paren">)</span> &#x2192; go.Figure<a class="reference internal" href="../_modules/optuna/visualization/_intermediate_values.html#plot_intermediate_values"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.visualization.plot_intermediate_values" title="永久链接至目标">¶</a></dt>
<dd><p>画出一个 study 中的全部 trial 的中间值。</p>
<p class="rubric">示例</p>
<p>下面的代码展示了如何绘制中间值。</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">optuna</span>

<span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
    <span class="k">return</span> <span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="o">**</span> <span class="mi">2</span>

<span class="k">def</span> <span class="nf">df</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
    <span class="k">return</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">x</span> <span class="o">-</span> <span class="mi">4</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">lr</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_loguniform</span><span class="p">(</span><span class="s2">&quot;lr&quot;</span><span class="p">,</span> <span class="mf">1e-5</span><span class="p">,</span> <span class="mf">1e-1</span><span class="p">)</span>

    <span class="n">x</span> <span class="o">=</span> <span class="mi">3</span>
    <span class="k">for</span> <span class="n">step</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">128</span><span class="p">):</span>
        <span class="n">y</span> <span class="o">=</span> <span class="n">f</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>

        <span class="n">trial</span><span class="o">.</span><span class="n">report</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">step</span><span class="o">=</span><span class="n">step</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">trial</span><span class="o">.</span><span class="n">should_prune</span><span class="p">():</span>
            <span class="k">raise</span> <span class="n">optuna</span><span class="o">.</span><span class="n">TrialPruned</span><span class="p">()</span>

        <span class="n">gy</span> <span class="o">=</span> <span class="n">df</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
        <span class="n">x</span> <span class="o">-=</span> <span class="n">gy</span> <span class="o">*</span> <span class="n">lr</span>

    <span class="k">return</span> <span class="n">y</span>

<span class="n">study</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">create_study</span><span class="p">()</span>
<span class="n">study</span><span class="o">.</span><span class="n">optimize</span><span class="p">(</span><span class="n">objective</span><span class="p">,</span> <span class="n">n_trials</span><span class="o">=</span><span class="mi">16</span><span class="p">)</span>

<span class="n">optuna</span><span class="o">.</span><span class="n">visualization</span><span class="o">.</span><span class="n">plot_intermediate_values</span><span class="p">(</span><span class="n">study</span><span class="p">)</span>
</pre></div>
</div>
<iframe src="../_static/plot_intermediate_values.html"
 width="100%" height="500px" frameborder="0">
</iframe><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>study</strong> -- <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 类，其包含的 trials 的目标函数中间值将参与绘图。</p>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p>A <code class="xref py py-class docutils literal notranslate"><span class="pre">plotly.graph_objs.Figure</span></code> object.</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt id="optuna.visualization.plot_optimization_history">
<code class="sig-prename descclassname">optuna.visualization.</code><code class="sig-name descname">plot_optimization_history</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">study</span><span class="p">:</span> <span class="n"><a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study">optuna.study.Study</a></span></em><span class="sig-paren">)</span> &#x2192; go.Figure<a class="reference internal" href="../_modules/optuna/visualization/_optimization_history.html#plot_optimization_history"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.visualization.plot_optimization_history" title="永久链接至目标">¶</a></dt>
<dd><p>画出一个 study 中所有 trial 的优化历史记录。</p>
<p class="rubric">示例</p>
<p>下面的代码展示了如何绘制优化历史记录。</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">optuna</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">x</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_uniform</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="o">-</span><span class="mi">100</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
    <span class="n">y</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_categorical</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">x</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">y</span>

<span class="n">study</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">create_study</span><span class="p">()</span>
<span class="n">study</span><span class="o">.</span><span class="n">optimize</span><span class="p">(</span><span class="n">objective</span><span class="p">,</span> <span class="n">n_trials</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>

<span class="n">optuna</span><span class="o">.</span><span class="n">visualization</span><span class="o">.</span><span class="n">plot_optimization_history</span><span class="p">(</span><span class="n">study</span><span class="p">)</span>
</pre></div>
</div>
<iframe src="../_static/plot_optimization_history.html"
 width="100%" height="500px" frameborder="0">
</iframe><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>study</strong> -- <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 类，其包含的 trials 的目标函数值将参与绘图。</p>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p>A <code class="xref py py-class docutils literal notranslate"><span class="pre">plotly.graph_objs.Figure</span></code> object.</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt id="optuna.visualization.plot_parallel_coordinate">
<code class="sig-prename descclassname">optuna.visualization.</code><code class="sig-name descname">plot_parallel_coordinate</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">study</span><span class="p">:</span> <span class="n"><a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study">optuna.study.Study</a></span></em>, <em class="sig-param"><span class="n">params</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span>List<span class="p">[</span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a><span class="p">]</span><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em><span class="sig-paren">)</span> &#x2192; go.Figure<a class="reference internal" href="../_modules/optuna/visualization/_parallel_coordinate.html#plot_parallel_coordinate"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.visualization.plot_parallel_coordinate" title="永久链接至目标">¶</a></dt>
<dd><p>绘制一个 study 中高维度参数的关系图。</p>
<p>注意，如果某个参数包含了缺失值，那么包含该参数的 trial 将不会被绘制。</p>
<p class="rubric">示例</p>
<p>下面的代码展示了如何绘制高维度参数的关系图。</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">optuna</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">x</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_uniform</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="o">-</span><span class="mi">100</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
    <span class="n">y</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_categorical</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">x</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">y</span>

<span class="n">study</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">create_study</span><span class="p">()</span>
<span class="n">study</span><span class="o">.</span><span class="n">optimize</span><span class="p">(</span><span class="n">objective</span><span class="p">,</span> <span class="n">n_trials</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>

<span class="n">optuna</span><span class="o">.</span><span class="n">visualization</span><span class="o">.</span><span class="n">plot_parallel_coordinate</span><span class="p">(</span><span class="n">study</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="s1">&#39;y&#39;</span><span class="p">])</span>
</pre></div>
</div>
<iframe src="../_static/plot_parallel_coordinate.html"
 width="100%" height="500px" frameborder="0">
</iframe><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>study</strong> -- <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 类，其包含的 trials 的目标函数值将参与绘图。</p></li>
<li><p><strong>params</strong> -- 需要可视化的参数列表，默认情况下将是全部参数。</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p>A <code class="xref py py-class docutils literal notranslate"><span class="pre">plotly.graph_objs.Figure</span></code> object.</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt id="optuna.visualization.plot_param_importances">
<code class="sig-prename descclassname">optuna.visualization.</code><code class="sig-name descname">plot_param_importances</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">study</span><span class="p">:</span> <span class="n"><a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study">optuna.study.Study</a></span></em>, <em class="sig-param"><span class="n">evaluator</span><span class="p">:</span> <span class="n">optuna.importance._base.BaseImportanceEvaluator</span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">params</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span>List<span class="p">[</span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a><span class="p">]</span><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em><span class="sig-paren">)</span> &#x2192; go.Figure<a class="reference internal" href="../_modules/optuna/visualization/_param_importances.html#plot_param_importances"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.visualization.plot_param_importances" title="永久链接至目标">¶</a></dt>
<dd><p>画出超参数的重要性</p>
<p class="rubric">示例</p>
<p>下面的代码展示了如何绘制超参数的重要性图</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">optuna</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">x</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_int</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
    <span class="n">y</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_float</span><span class="p">(</span><span class="s2">&quot;y&quot;</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
    <span class="n">z</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_float</span><span class="p">(</span><span class="s2">&quot;z&quot;</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.5</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">x</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">y</span> <span class="o">**</span> <span class="mi">3</span> <span class="o">-</span> <span class="n">z</span> <span class="o">**</span> <span class="mi">4</span>

<span class="n">study</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">create_study</span><span class="p">(</span><span class="n">sampler</span><span class="o">=</span><span class="n">optuna</span><span class="o">.</span><span class="n">samplers</span><span class="o">.</span><span class="n">RandomSampler</span><span class="p">())</span>
<span class="n">study</span><span class="o">.</span><span class="n">optimize</span><span class="p">(</span><span class="n">objective</span><span class="p">,</span> <span class="n">n_trials</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span>

<span class="n">optuna</span><span class="o">.</span><span class="n">visualization</span><span class="o">.</span><span class="n">plot_param_importances</span><span class="p">(</span><span class="n">study</span><span class="p">)</span>
</pre></div>
</div>
<iframe src="../_static/plot_param_importances.html"
 width="100%" height="500px" frameborder="0">
</iframe><div class="admonition seealso">
<p class="admonition-title">参见</p>
<p>该函数对 <a class="reference internal" href="importance.html#optuna.importance.get_param_importances" title="optuna.importance.get_param_importances"><code class="xref py py-func docutils literal notranslate"><span class="pre">optuna.importance.get_param_importances()</span></code></a> 的结果进行可视化。</p>
</div>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>study</strong> -- 优化结束的 study.</p></li>
<li><p><strong>evaluator</strong> -- 参数重要性求解器。它指定评估重要性的算法。默认情况下它会被设定成 <code class="xref py py-class docutils literal notranslate"><span class="pre">MeanDecreaseImpurityImportanceEvaluator</span></code>.</p></li>
<li><p><strong>params</strong> -- 参与评估的参数名列表。如果设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">None</span></code></a> 的话，全部的、属于所有已完成 trial 的参数都将参与评估。</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p>A <code class="xref py py-class docutils literal notranslate"><span class="pre">plotly.graph_objs.Figure</span></code> object.</p>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>v1.5.0 版本中新加入的试验性特性。在未来的版本中，该接口可能在没有预先告知的情况下改变。 具体参见 <a class="reference external" href="https://github.com/optuna/optuna/releases/tag/v1.5.0">https://github.com/optuna/optuna/releases/tag/v1.5.0</a>.</p>
</div>
</dd></dl>

<dl class="py function">
<dt id="optuna.visualization.plot_slice">
<code class="sig-prename descclassname">optuna.visualization.</code><code class="sig-name descname">plot_slice</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">study</span><span class="p">:</span> <span class="n"><a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study">optuna.study.Study</a></span></em>, <em class="sig-param"><span class="n">params</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span>List<span class="p">[</span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a><span class="p">]</span><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em><span class="sig-paren">)</span> &#x2192; go.Figure<a class="reference internal" href="../_modules/optuna/visualization/_slice.html#plot_slice"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.visualization.plot_slice" title="永久链接至目标">¶</a></dt>
<dd><p>绘制一个 study 中的参数关系切片图。</p>
<p>注意，如果某个参数包含了缺失值，那么包含该参数的 trial 将不会被绘制。</p>
<p class="rubric">示例</p>
<p>下面的代码展示了如何绘制参数关系切片图。</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">optuna</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">x</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_uniform</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="o">-</span><span class="mi">100</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
    <span class="n">y</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_categorical</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
    <span class="k">return</span> <span class="n">x</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">+</span> <span class="n">y</span>

<span class="n">study</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">create_study</span><span class="p">()</span>
<span class="n">study</span><span class="o">.</span><span class="n">optimize</span><span class="p">(</span><span class="n">objective</span><span class="p">,</span> <span class="n">n_trials</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>

<span class="n">optuna</span><span class="o">.</span><span class="n">visualization</span><span class="o">.</span><span class="n">plot_slice</span><span class="p">(</span><span class="n">study</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="s1">&#39;y&#39;</span><span class="p">])</span>
</pre></div>
</div>
<iframe src="../_static/plot_slice.html" width="100%" height="500px" frameborder="0">
</iframe><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>study</strong> -- <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 类，其包含的 trials 的目标函数值将参与绘图。</p></li>
<li><p><strong>params</strong> -- 需要可视化的参数列表，默认情况下将是全部参数。</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p>A <code class="xref py py-class docutils literal notranslate"><span class="pre">plotly.graph_objs.Figure</span></code> object.</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt id="optuna.visualization.is_available">
<code class="sig-prename descclassname">optuna.visualization.</code><code class="sig-name descname">is_available</code><span class="sig-paren">(</span><span class="sig-paren">)</span> &#x2192; <a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(在 Python v3.8)">bool</a><a class="reference internal" href="../_modules/optuna/visualization/_utils.html#is_available"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.visualization.is_available" title="永久链接至目标">¶</a></dt>
<dd><p>返回可视化是否可用。</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p><a class="reference internal" href="#module-optuna.visualization" title="optuna.visualization"><code class="xref py py-mod docutils literal notranslate"><span class="pre">visualization</span></code></a> 模块依赖 4.0.0 或者更高版本的 plotly. 如果在你的环境中对应版本的 ploty没有安装的话，该函数将返回 <a class="reference external" href="https://docs.python.org/3/library/constants.html#False" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">False</span></code></a>. 此时，请执行 <code class="docutils literal notranslate"><span class="pre">$</span> <span class="pre">pip</span> <span class="pre">install</span> <span class="pre">-U</span> <span class="pre">plotly&gt;=4.0.0</span></code> 来安装 plotly.</p>
</div>
<dl class="field-list simple">
<dt class="field-odd">返回</dt>
<dd class="field-odd"><p>如果可视化可用的话，返回 <a class="reference external" href="https://docs.python.org/3/library/constants.html#True" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">True</span></code></a>, 否则返回 <a class="reference external" href="https://docs.python.org/3/library/constants.html#False" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">False</span></code></a>.</p>
</dd>
</dl>
</dd></dl>

</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="../faq.html" class="btn btn-neutral float-right" title="常见问题" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="trial.html" class="btn btn-neutral float-left" title="Trial" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, Optuna Contributors.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
    <a href="../privacy.html">Privacy Policy</a>.
     


</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
    <!-- Theme Analytics -->
    <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-55135190-8', 'auto');
    ga('send', 'pageview');
    </script>

    
   

</body>
</html>